#include <vector>
#include <map>
#include <functional>
#include <stack>
#include <string>
using namespace std;

class Solution {
public:
    int evalRPN(vector<string>& tokens) {

        map<string, std::function<int(int, int)>> matchOpr = {
        {"+", [](int x, int y){return x + y;}},
        {"-", [](int x, int y){return x - y;}},
        {"*", [](int x, int y){return x * y;}},
        {"/", [](int x, int y){return x / y;}}
        };

        stack<int> st;

        for(auto str : tokens){
            if(matchOpr.count(str)){
                int right = st.top();
                st.pop();
                int left = st.top();
                st.pop();

                st.push(matchOpr[str](left, right));
            }
            else st.push(stoi(str));
        }

        return st.top();
    }
};